package com.zxcrm.web.controller.zxcrm;

import com.zxcrm.common.annotation.Log;
import com.zxcrm.common.core.controller.BaseController;
import com.zxcrm.common.core.domain.AjaxResult;
import com.zxcrm.common.core.page.TableDataInfo;
import com.zxcrm.common.enums.BusinessType;
import com.zxcrm.common.utils.poi.ExcelUtil;
import com.zxcrm.zxcrm.domain.ZxcrmPlan;
import com.zxcrm.zxcrm.service.IZxcrmPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 计划Controller
 * 
 * @author xu
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/zxcrm/plan")
public class ZxcrmPlanController extends BaseController {
    @Autowired
    private IZxcrmPlanService zxcrmPlanService;

    /**
     * 查询计划列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxcrmPlan zxcrmPlan) {
        startPage();
        List<ZxcrmPlan> list = zxcrmPlanService.selectZxcrmPlanList(zxcrmPlan);
        return getDataTable(list);
    }

    /**
     * 导出计划列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:export')")
    @Log(title = "计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxcrmPlan zxcrmPlan) {
        List<ZxcrmPlan> list = zxcrmPlanService.selectZxcrmPlanList(zxcrmPlan);
        ExcelUtil<ZxcrmPlan> util = new ExcelUtil<ZxcrmPlan>(ZxcrmPlan.class);
        util.exportExcel(response, list, "计划数据");
    }

    /**
     * 获取计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zxcrmPlanService.selectZxcrmPlanById(id));
    }

    /**
     * 新增计划
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:add')")
    @Log(title = "计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxcrmPlan zxcrmPlan) {
        return toAjax(zxcrmPlanService.insertZxcrmPlan(zxcrmPlan));
    }

    /**
     * 修改计划
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:edit')")
    @Log(title = "计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxcrmPlan zxcrmPlan) {
        return toAjax(zxcrmPlanService.updateZxcrmPlan(zxcrmPlan));
    }

    /**
     * 删除计划
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:remove')")
    @Log(title = "计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zxcrmPlanService.deleteZxcrmPlanByIds(ids));
    }

    /**
     * 我的计划
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:list')")
    @GetMapping("/myPlan")
    public AjaxResult myPlanList(ZxcrmPlan zxcrmPlan) {
        List<Map<String, Object>> list = zxcrmPlanService.selectZxcrmMyPlanList(zxcrmPlan);
        return AjaxResult.success(list);
    }

    /**
     * 团队计划
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:plan:list')")
    @GetMapping("/teamPlan")
    public AjaxResult teamPlanList(ZxcrmPlan zxcrmPlan) {
        List<Map<String, Object>> list = zxcrmPlanService.selectZxcrmTeamPlanList(zxcrmPlan);
        return AjaxResult.success(list);
    }
}
